package com.wisdom.benefit.jufa.utils;

import android.widget.ImageView;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.FitCenter;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.wisdom.benefit.jufa.R;

public final class ImageLoader {

    public static void loadImage(ImageView imageView, String imgUrl, int radius) {
        if (radius <= 0) {
            loadImage(imageView, imgUrl);
            return;
        }
        GlideApp.with(imageView.getContext())
                .asBitmap()
                .load(imgUrl)
                .placeholder(R.drawable.ic_load_img_placeholder)
                .error(R.drawable.ic_load_img_error)
                .transform(new CenterCrop(), new RoundedCorners(DisplayUtil.dip2px(imageView.getContext(), radius)))
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                .into(imageView);
    }

    public static void loadImage(ImageView imageView, String imgUrl) {
        GlideApp.with(imageView.getContext())
                .asBitmap()
                .load(imgUrl)
                .placeholder(R.drawable.ic_load_img_placeholder)
                .error(R.drawable.ic_load_img_error)
                .transform(new CenterCrop())
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                .into(imageView);
    }

    public static void loadImageFit(ImageView imageView, String imgUrl) {
        GlideApp.with(imageView.getContext())
                .asBitmap()
                .load(imgUrl)
                .placeholder(R.drawable.ic_load_img_placeholder)
                .error(R.drawable.ic_load_img_error)
                .transform(new FitCenter())
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                .into(imageView);
    }
}
